/**
 * 
 */
package org.picWeb.view.ajax;

import javax.servlet.http.HttpSession;

import org.picWeb.view.service.ObjectDaoInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 * @version 1.0 org.picWeb.view/SysUserAjax.java 2011-7-3
 */
@Service("sysUserAjax")
public class SysUserAjax {

	@Autowired
	private ObjectDaoInterface objectDao;

	public boolean loginOut(HttpSession session) {
		session.removeAttribute("user");

		return true;
	}

	public boolean checkUserNameRepeat(String id, String userName) {
		String hql = null;
		String[] params = null;

		if (null == id || id.length() == 0) {
			hql = "from SysUser t where t.userName = ?";
			params = new String[] { userName };
		} else {
			hql = "from SysUser t where t.userName = ? and id != ?";
			params = new String[] { userName, id };
		}

		Object obj = objectDao.findOne(hql, params);
		if (null != obj) {
			return false;
		}

		return true;
	}
}
